package com.lagou.filter;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

@Activate(group = {CommonConstants.CONSUMER,CommonConstants.PROVIDER})
public class TransportIPFilter implements Filter {
    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {

        if(RpcContext.getContext().isConsumerSide()){
            System.out.println("consumer ip: "+RpcContext.getContext().getAttachment("ip"));
        }
        if(RpcContext.getContext().isProviderSide()){
            System.out.println("provider ip: "+RpcContext.getContext().getAttachment("ip"));
        }
        return invoker.invoke(invocation);
    }
}
